package org.example.studentmanager.controller;

import org.example.studentmanager.common.utils.R;
import org.example.studentmanager.entity.ClassInfo;
import org.example.studentmanager.entity.Clazz;
import org.example.studentmanager.entity.Student;
import org.example.studentmanager.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/class")
public class ClassController {

    @Autowired
    private ClassService classService;

    // 根据教师id查询班级的所有学生
    @GetMapping("/query/students/{class_id}")
    public R<List<ClassInfo>> findStudentsOfClass(@PathVariable("class_id") Integer id) {
        return R.success(classService.findStudentsOfClass(id));
    }

    /**
     * 通过多id查询学生信息
     * @param id 教师id
     * @param courseId 课程id
     * @return 学生信息列表
     * */
    @GetMapping("/query/students")
    public R<List<Student>> findStudentsOfClassByIds(@RequestParam("teacherId") Integer id, @RequestParam("courseId") Integer courseId) {
        return R.success(classService.findStudentsByClassId(id,courseId));
    }

    // 根据课程名查询班级
    @GetMapping("/query/course")
    public R<List<Clazz>> findClazzByCourseName(@RequestParam("name") String name) {
        return R.success(classService.findClazzByCourseName(name));
    }

    // 删除班级信息
    @GetMapping("/delete/{class_id}")
    public void delete(@PathVariable("class_id") Integer id) {
        classService.delete(id);
    }

    // 向班级添加学生
    // TODO 这里记得改成请求参数的样子
    @GetMapping("/student/add/{class_id}/{student_id}")
    public void addStudent(@PathVariable("class_id") Integer classId, @PathVariable("student_id") Integer studentId) {
        classService.addStudent(classId, studentId);
    }

    @PostMapping("/insert")
    public void insertClass(@RequestBody Clazz clazz) {
        classService.insertClass(clazz);
    }

}
